package com.rcp.steve.crm.navigation;

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import com.rcp.steve.connection.ApplicationUserInfo;
import com.rcp.steve.crm.editor.CountyProductQueryEditor;
import de.vogella.jface.treeviewer.model.CountyProductTodoMockModel;
import de.vogella.jface.treeviewer.model.Todo;
import de.vogella.jface.treeviewer.provider.TodoContentProvider;
import de.vogella.jface.treeviewer.provider.TodoLabelProvider;

public class CountyProductView extends ParentNavigation {
	public static final String ID = "com.rcp.steve.crm.navigation.CountyProductView";
	public void createPartControl(Composite parent) {
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL
		        | SWT.V_SCROLL);
		viewer.setContentProvider(new TodoContentProvider());
		viewer.setLabelProvider(new TodoLabelProvider());
		viewer.setAutoExpandLevel(2);
		viewer.setInput(new CountyProductTodoMockModel());
		viewer.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(DoubleClickEvent event) {
				IStructuredSelection selection = (IStructuredSelection) event
						.getSelection();
				Todo todo = (Todo) selection.getFirstElement();
				if(todo.getUrl()==null||"".equals(todo.getUrl())){
					return;
				}
				IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
				IWorkbenchPage page = window.getActivePage();
				try {
				   page.openEditor(todo, CountyProductQueryEditor.ID);
				} catch (PartInitException e) {
					e.printStackTrace();
				}
			}
		});
	}
}